//
//  Util.h
//  PhotoSnow
//
//  Created by 为为 on 13-5-5.
//  Copyright (c) 2013年 为为. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

// random
#define RAND_IN_1	((float)rand()/RAND_MAX)
#define RAND_IN_RANGE(low, high) ((low)+RAND_IN_1*((high)-(low)))

// stringify
#define STRINGIFY(a)	@#a

// localize
#define LOC(a)		NSLocalizedString(a, nil)

// app version
#define APP_VERSION		[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]

// exception
#define CATCH_EXCEPTION_BEGIN   @try {
#define CATCH_EXCEPTION_END		}   @catch(NSException* e) { NSLog(@"File:%s, Line:%d, %@", __FILE__, __LINE__, e);};

// color
#define RGBA(r,g,b,a)  [UIColor colorWithRed:r green:g blue:b alpha:a]

UIColor* ColorFromColorWithAlpah(UIColor* color, CGFloat alpha);
UIImage* ImageFromColor(UIColor* color);

// point
CGPoint NormalizePoint(CGPoint pt);
CGPoint MulPointWithPoint(CGPoint pt1, CGPoint pt2);
CGPoint MulPointWithValue(CGPoint pt1, CGFloat val);
CGPoint AddPointWithPoint(CGPoint pt1, CGPoint pt2);
CGPoint AddPointWithValue(CGPoint pt1, CGFloat val);
CGPoint SubPointWithPoint(CGPoint pt1, CGPoint pt2);
CGPoint SubPointWithValue(CGPoint pt1, CGFloat val);
CGPoint DivPointWithPoint(CGPoint pt1, CGPoint pt2);
CGPoint DivPointWithValue(CGPoint pt1, CGFloat val);

// rect
CGRect ScaleRectSize(CGRect rect, CGFloat widthRatio, CGFloat heightRatio);
bool CircleContainsPoint(CGRect rect, CGPoint point);

// image
NSString *DocumentDirectory();
void SaveImageToDocument(UIImage* image, NSString* name);
bool SaveImageToPathCreatePathIfNeed(UIImage* image, NSString* path);
NSArray* GetImageNameArray(NSString* baseName, int startIndex);

// base64
NSString *DataToBase64String(NSData* data);
NSString *StringToBase64String(NSString *string);
NSString *StringFromBase64String(NSString *string);

// string
int IndexOfString(NSString* s1, NSString* s2);
NSString* SubStingWithIndex(NSString* str, int from, int to);
BOOL IsStringNullOrEmpty(NSString* string);

// xib
NSObject* GetObjectFromXib(Class cls, NSString* xibName);

// view
void ChangeViewsSuperView(UIView* view, UIView* toSuperView);

// lan
NSString* PreferredLanguage();
bool IsLanguageSimpleChinese();
bool IsLanguageTraditionChinese();

// path
bool CreatePaths(NSString* path);

// url
NSString* UrlEncode(NSString* str);
NSString* UrlEncodePartInString(NSString* string,NSString* seprator);
NSString* NormalizeUrlScheme(NSString* scheme);
bool CanOpenUrlScheme(NSString* schemeString);

// itunes
void JumpToAppStoreWithAppID(NSString* appid);

// device token
NSString* StripDeviceToken(NSString* rawToken);

// backup
BOOL addSkipBackupAttributeToItemAtURL(NSURL *URL);